package _go

import (
	"context"
	"gitee.com/kmyss/gf-ex/yslog"
	"gitee.com/kmyss/gf-ex/ysos"
	"gitee.com/kmyss/ys-cli/internal/model"
	"gitee.com/kmyss/ys-cli/internal/service"
	"github.com/gogf/gf/v2/os/glog"
)

func init() {
	service.RegisterGo(&sGo{})
}

type sGo struct {
	l *glog.Logger
}

func (s *sGo) log() *glog.Logger {
	if s.l == nil {
		s.l = yslog.Log("logic.go")
	}
	return s.l
}

func (s *sGo) Build(ctx context.Context, in *model.GolangBuildInput) (err error) {

	// 创建临时文件
	err = s.createTmpBuildCfg(ctx, in)
	if err != nil {
		return
	}

	defer s.clearTmpBuildCfg(ctx, in.BuildCfg)

	err = s.doBuild(ctx, in)
	if err != nil {
		return
	}

	ysos.OpenDir(s.buildPath(ctx, in.Version))

	return
}
